// 对数组进行过滤操作

const names = [ '孙悟空' , '诸葛亮' , '敖广' , '小姜' , '敖闰' ];

// Array.prototype.every( callback( element [, index [, array ] ] ) [, thisArg] )
let result = names.every( (e,i,a) => { 
    console.log( i , e );
    return e.length > 2 
});
console.log( result );

console.log( '- '.repeat(30) );

// Array.prototype.some( callback( element [, index [, array ] ] ) [, thisArg] )
result = names.some( (e,i,a)=>{
    console.log( i , e );
    return e.startsWith( '敖' ) ;
});
console.log( result );

// Array.prototype.filter( callback( element [, index [, array ] ] ) [, thisArg] )
let array = names.filter( (e,i,a)=>{
    console.log( i , e );
    return e.startsWith( '敖' ) ;
});

console.log( array );

console.log( '= '.repeat( 30 ) );

let pandas = [
    { id: 1002 , name: '小美' , age: 10 },
    { id: 3456 , name: '大美' , age: 11 },
    { id: 1234 , name: '小圆' , age: 9 },
    { id: 4321 , name: '小小圆' , age: 8 }
];

console.log( pandas.every( e => e.age >= 10 ) );

console.log( pandas.some( e => e.age >= 10 ) );

let ps = pandas.filter( e => e.age >= 10 );
console.log( ps );

// 总结:
// Array.prototype.every( callback [ , thisArg ] )
// Array.prototype.some( callback [ , thisArg ] )
// Array.prototype.filter( callback [ , thisArg ] )